import 'package:flutter/material.dart';
import 'package:flutter_buisiness_2006a/bean/category_parent_bean_result.dart';
import '../bean/category_goods_list_bean_result.dart';

class CategoryProvider with ChangeNotifier {
  //二级列表的数据源
  List<CategoryChildBean> childCategoryList = [];

  //三级列表的数据源
  List<CategoryGoodsListBean> categoryGoodsList = [];

  CategoryGoodsListBean? goodsListBean;

  int size = 10; //为了之后在分类列表中下拉加载而添加的size

  int parentIndex = 0; //一级分类的下标
  int childIndex = 0; //二级列表的下标

  int childId = 14;

  changeChildIndex(index) {
    childIndex = index;
    notifyListeners();
  }

  changeParentIndex(index) {
    parentIndex = index;
    notifyListeners();
  }

  setChildCategoryList(list) {
    childCategoryList = list;
    notifyListeners();
  }

  //为了下拉刷新时使用的追加数据源
  addCategoryGoodsList(list) {
    categoryGoodsList.addAll(list);
    print(list.toString());
    notifyListeners();
  }

  //初始化时或者切换tab时需要重设初始化数据源
  setCategoryGoodsList(list) {
    categoryGoodsList = list;
    notifyListeners();
  }

  //添加每页请求的数量
  addSize() {
    size += 10;
    notifyListeners();
  }

  setChildId(childId) {
    this.childId = childId;
    notifyListeners();
  }

  setCategoryGoodsListBean(CategoryGoodsListBean goodsListBean) {
    this.goodsListBean = goodsListBean;
    notifyListeners();
  }
}
